﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.SCM.App.Credit.Report;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WSDZ.KM.ZH.CreditFileToCreditSearch.CreditFile
{
    [Description("信用状况查询"), HotUpdate]
    public class CreditSearch: CreditInfoService
    {
        public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            base.BuilderReportSqlAndTempTable(filter, tableName);
            object openObj;
            string custNumber = string.Empty;
            if (filter.CustomParams.TryGetValue("OpenParameter", out openObj))
            {
                var openParam = (Dictionary<string, object>)openObj;
                object sqlFilter;
                openParam.TryGetValue("custId", out sqlFilter);
                if (sqlFilter.ToInt32V1()!=0)
                    custNumber = DBUtils.ExecuteScalar(Context, $@"select FNUMBER from T_BD_CUSTOMER where FCUSTID={sqlFilter}", "");

            }
            if (!custNumber.IsNullOrEmptyOrWhiteSpace())
            {
                //string tname = $@"Temp_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}";
                //string sql_u = $@"/*dialect*/ insert into {tname} select * from {tableName} where FCREDITOBJECTCODE='{custNumber}'";
                //tableName = tname;
                string sql_d = $@"/*dialect*/ delete {tableName} where ISNULL(FCREDITOBJECTCODE,'')<>'{custNumber}'";
                DBUtils.Execute(Context, sql_d);
            }
           
        }

    }
}
